home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
misc
/
emu
/
ATUtilities.lha
/
ATUtilities
/
tdi.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-09-26
|
39KB
|
1,623 lines
/* ******************************************************************* */
/* ** ** */
/* ** ATUtilities Disk Transfer ** */
/* ** Copright (C) 1992-1993 by Thomas Dreibholz ** */
/* ** All rights reserved ** */
/* ** ** */
/* ******************************************************************* */
ULONG xxx=0;
#include <devices/trackdisk.h>
#include "janus.h"
#include "ATUtilities.h"
#define REGISTER_NOPROGS
#include "register.h"
#define BIT15 (1<<15)
struct UDevice
{
UBYTE Name[100];
UWORD Unit;
ULONG Heads;
ULONG SectorsPerTrack;
ULONG Tracks;
UWORD Motor;
BOOL File;
};
struct CacheBlock
{
ULONG Changes;
ULONG Offset;
UWORD Length;
UBYTE *Memory;
UBYTE *NextCacheBlock;
};
struct TDevice
{
BOOL Valid;
ULONG Changes;
struct FileHandle *FileHandle;
struct IOStdReq *Request;
struct MsgPort *Port;
LONG Device;
struct CacheBlock *FirstCacheBlock;
struct Remember *CacheRemember;
};
struct UDevice ud[6]=
{
"trackdisk.device",0,2,11,80,4,FALSE,
"trackdisk.device",1,2,11,80,4,FALSE,
"trackdisk.device",0,1,11,80,4,FALSE,
"trackdisk.device",1,1,11,80,4,FALSE,
"DH0:Trashcan/File01",0,2,11,80,0,TRUE,
"DH0:Trashcan/File02",0,4,16,200,0,TRUE
};
struct TDevice td[6]=
{
TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
TRUE,10000000L,NULL,NULL,NULL,-1L,0L,0L,
};
UWORD Active;
UWORD MotorCNT[6]={0,0,0,0,0,0};
UBYTE *TransferPort="ATUtilities Disk Transfer";
UBYTE *PrefsName="AT:Prefs/DiskTransfer.prefs";
UBYTE *HelpName="AT:Help/DiskTransfer.help";
LONG JanusSignal;
LONG PortSignal;
LONG TaskSignal;
ULONG JanusSignalMask;
ULONG PortSignalMask;
ULONG WaitSignalMask;
ULONG TaskSignalMask;
ULONG AppSignalMask;
ULONG Signale;
struct JanusBase *JanusBase;
struct Library *GfxBase;
struct Library *IntuitionBase;
struct Library *ATUtilitiesBase;
struct Process *MotorTask;
struct Task *MainTask;
struct MsgPort *TaskPort,*ReplyPort;
struct ExtSetupSig *ExtSetupSig;
struct Window *WindowPtr;
struct RastPort *rp;
struct CommMemory *jhbyte,*jhword;
struct AppManager *app;
struct Message Message;
struct Message *AppMessage;
#ifdef SHAREWARE
VOID RegCheck();
#endif
VOID HandleInt();
VOID WriteCache();
VOID ShowInfo();
VOID Motor();
VOID EditiereLW();
VOID ZeigeLW();
BOOL EinstellungenAendern();
BOOL AddCache();
VOID InstallAll();
VOID UninstallAll();
VOID InstallFile();
VOID UninstallFile();
VOID InstallDevice();
VOID UninstallDevice();
VOID OpenAll();
VOID CloseAll();
VOID Bearbeite();
VOID BearbeiteFile();
WORD ChangeCheck();
VOID CalcFAT();
VOID MotorOnOff();
VOID Format();
VOID Kopiere();
UBYTE *mem;
struct MsgPort *Port;
/* Installationsroutine */
VOID main()
{
REGISTER UWORD i;
REGISTER BOOL bool;
OpenAll();
bool=FALSE;
while(bool==FALSE)
{
printf("w %lx",WaitSignalMask);
Signale=Wait(WaitSignalMask);
puts("sr");
if(Signale & PortSignalMask)
{
puts("ATKeyboard");
i=Received(Port);
switch(i)
{
case UTILITY_CALL:
bool=EinstellungenAendern();
break;
case UTILITY_QUIT:
bool=ExitWarning();
break;
case UTILITY_INFO:
ShowInfo();
break;
case UTILITY_HELP:
Help(HelpName,0);
break;
}
}
if(Signale & JanusSignalMask)
{
HandleInt();
}
if(Signale & TaskSignalMask)
{
for(i=0;i<6;i++)
{
if(MotorCNT[i]>0)
{
MotorCNT[i]--;
if(MotorCNT[i]==0)
{
printf("MOTOR %ld\n",i);
WriteCache(i);
MotorOnOff(i,0);
printf("``````````````````\n");
}
}
}
}
if(app!=NULL)
{
if(Signale & AppSignalMask)
{
AppMessage=GetMsg(app->Port);
if(AppMessage!=NULL)
{
ReplyMsg(AppMessage);
bool=EinstellungenAendern();
}
}
}
}
CloseAll();
}
/* PC-Befehle ausführen */
VOID HandleInt()
{
REGISTER BOOL bool;
REGISTER UWORD i,l;
REGISTER ULONG o;
printf("C%ld\n",jhword->Arg1);
switch(jhword->Arg1)
{
case 1:
if(ud[Active].File==FALSE)
{
l=jhword->Arg2*512;
o=jhword->Arg3*512;
bool=AddCache(&jhword->Memory,o,l);
if(bool==FALSE)
{
puts("W-ERROR");
MotorCNT[Active]=ud[Active].Motor;
td[Active].Request->io_Data=mem;
CopyMemQuick(&jhword->Memory,mem,l);
td[Active].Request->io_Data=mem;
td[Active].Request->io_Length=l;
td[Active].Request->io_Offset=o;
td[Active].Request->io_Command=CMD_WRITE;
i=DoIO(td[Active].Request);
if(i!=0)
{
switch(i)
{
case 28:
jhword->Arg2=0+BIT15;
break;
case 29:
jhword->Arg2=15+BIT15;
break;
default:
jhword->Arg2=10+BIT15;
break;
}
}
else
{
jhword->Arg2=0;
}
td[Active].Request->io_Command=CMD_UPDATE;
i=DoIO(td[Active].Request);
if(i!=0)
{
switch(i)
{
case 28:
jhword->Arg2=0+BIT15;
break;
case 29:
jhword->Arg2=15+BIT15;
break;
default:
jhword->Arg2=10+BIT15;
break;
}
}
else
{
jhword->Arg2=0;
}
}
/* puts("ok1"); */
}
else
{
l=jhword->Arg2*512;
Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
i=Write(td[Active].FileHandle,&jhword->Memory,l);
if(i==l)
{
jhword->Arg2=0;
}
else
{
jhword->Arg2=10+BIT15;
}
}
break;
case 2:
if(ud[Active].File==FALSE)
{
puts("READ");
WriteCache(Active);
MotorCNT[Active]=ud[Active].Motor;
td[Active].Request->io_Data=mem;
l=jhword->Arg2*512;
td[Active].Request->io_Length=l;
td[Active].Request->io_Offset=jhword->Arg3*512;
td[Active].Request->io_Command=CMD_READ;
i=DoIO(td[Active].Request);
if(i!=0)
{
switch(i)
{
case 29:
jhword->Arg2=15+BIT15;
break;
default:
jhword->Arg2=11+BIT15;
break;
}
}
else
{
CopyMemQuick(mem,&jhword->Memory,l);
jhword->Arg2=0;
}
}
else
{
l=jhword->Arg2*512;
Seek(td[Active].FileHandle,jhword->Arg3*512,OFFSET_BEGINNING);
i=Read(td[Active].FileHandle,&jhword->Memory,l);
if(i==l)
{
jhword->Arg2=0;
}
else
{
jhword->Arg2=15+BIT15;
}
}
break;
case 3:
if(ud[Active].File==FALSE)
{
MotorCNT[Active]=ud[Active].Motor;
td[Active].Request->io_Command=CMD_UPDATE;
/*
i=DoIO(td[Active].Request);
*/
i=0;
if(i!=0)
{
switch(i)
{
case 28:
jhword->Arg2=0+BIT15;
break;
case 29:
jhword->Arg2=15+BIT15;
break;
default:
jhword->Arg2=10+BIT15;
break;
}
}
else
{
jhword->Arg2=0;
}
}
break;
case 4:
if(ud[Active].File==FALSE)
{
jhword->Arg2=ChangeCheck(Active);
}
else
{
jhword->Arg2=1;
}
break;
case 5:
jhword->Arg2=ud[Active].Tracks*ud[Active].Heads*ud[Active].SectorsPerTrack;
jhword->Arg3=ud[Active].Tracks;
jhword->Arg4=ud[Active].Heads;
CalcFAT(Active);
if(ud[Active].File==FALSE) jhword->Arg7=0; else jhword->Arg7=1;
break;
case 6:
for(i=0;i<6;i++)
{
MotorOnOff(i,1);
MotorCNT[i]=ud[Active].Motor;
}
break;
case 10:
Format();
break;
case 20:
Kopiere();
break;
case 100:
if(td[jhword->Arg2].Valid==FALSE)
{
jhword->Arg2=2+BIT15;
}
else
{
Active=jhword->Arg2;
jhword->Arg2=0;
}
break;
default:
break;
}
SendJanusInt(29);
printf("~~~~~~~~~~~~~~~~~~~~~\n");
}
/* Diskettenwechsel prüfen */
WORD ChangeCheck(num)
UWORD num;
{
REGISTER LONG i;
td[num].Request->io_Command=TD_CHANGENUM;
DoIO(td[num].Request);
i=td[num].Request->io_Actual;
if(i!=td[num].Changes)
{
td[num].Changes=i;
return(0xFF);
}
return(1);
}
/* Laufwerke öffnen */
VOID InstallAll()
{
REGISTER LONG i;
for(i=0;i<6;i++)
{
if(ud[i].File==FALSE)
{
InstallDevice(i);
}
else
{
InstallFile(i);
}
}
}
/* Laufwerke schließen */
VOID UninstallAll()
{
REGISTER LONG i;
for(i=0;i<6;i++)
{
if(ud[i].File==FALSE)
{
UninstallDevice(i);
}
else
{
UninstallFile(i);
}
}
}
VOID InstallDevice(num)
UWORD num;
{
td[num].Port=CreatePort(0L,0L);
if(td[num].Port!=NULL)
{
td[num].Request=CreateExtIO(td[num].Port,200);
if(td[num].Request!=NULL)
{
td[num].Device=OpenDevice(&ud[num].Name,ud[num].Unit,td[num].Request,0);
if(td[num].Device!=0)
{
UninstallDevice(num);
}
}
else
{
UninstallDevice(num);
}
}
else
{
UninstallDevice(num);
}
}
VOID UninstallDevice(num)
UWORD num;
{
if(td[num].Valid==TRUE)
{
if(td[num].Device==0L) CloseDevice(td[num].Request);
if(td[num].Request) DeleteExtIO(td[num].Request);
if(td[num].Port) DeletePort(td[num].Port);
td[num].Valid=FALSE;
}
}
/* Datei installieren */
VOID InstallFile(num)
UWORD num;
{
REGISTER ULONG i,j;
register struct FileLock *lock;
td[num].Valid=FALSE;
lock=Lock(&ud[num].Name,ACCESS_READ);
if(lock!=NULL)
{
UnLock(lock);
td[num].FileHandle=Open(&ud[num].Name,MODE_READWRITE);
if(td[num].FileHandle!=NULL)
{
Seek(td[num].FileHandle,0,OFFSET_END);
i=Seek(td[num].FileHandle,0,OFFSET_BEGINNING);
j=512L*(ULONG)ud[num].Tracks*(ULONG)ud[num].Heads*(ULONG)ud[num].SectorsPerTrack;
if(i!=j)
{
MultiRequest("Inkompatible Dateilänge bei LW-Datei",&ud[num].Name,"Okay",NULL);
Close(td[num].FileHandle);
}
else
{
td[num].Valid=TRUE;
}
}
}
}
VOID UninstallFile(num)
UWORD num;
{
if(td[num].Valid==TRUE)
{
if(td[num].FileHandle) Close(td[num].FileHandle);
td[num].Valid=FALSE;
}
}
/* Installationsroutine */
VOID OpenAll()
{
REGISTER UWORD i;
register struct MsgPort *p;
register struct FileHandle *fh;
ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
if(ATUtilitiesBase==NULL)
{
printf("Kann ATUtilities-Library nicht öffnen.\n");
CloseAll();
}
GfxBase=OpenLibrary("graphics.library",0L);
IntuitionBase=OpenLibrary("intuition.library",0L);
if((GfxBase==NULL)||(IntuitionBase==NULL))
{
CloseAll();
}
p=FindPort(TransferPort);
if(p!=NULL)
{
InfoRequest("ATUtilities Disk Transfer ist schon aktiv.");
CloseAll();
}
MainTask=FindTask(NULL);
SetTaskPri(MainTask,10);
JanusBase=OpenLibrary("janus.library",0L);
if(JanusBase==NULL)
{
ErrorRequest(ERROR_JANUS);
CloseAll();
}
TaskSignal=AllocSignal(-1L);
if(TaskSignal==-1L)
{
ErrorRequest(ERROR_SIGNAL);
CloseAll();
}
Port=CreatePort(TransferPort,0L);
if(Port==NULL)
{
ErrorRequest(ERROR_MPORT);
CloseAll();
}
fh=Open(PrefsName,MODE_OLDFILE);
if(fh!=NULL)
{
Read(fh,&ud,sizeof(struct UDevice)*6);
Close(fh);
}
InstallAll();
mem=AllocMem(PUBLIC_PAGESIZE,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
if(mem==NULL)
{
ErrorRequest(ERROR_ALLOC);
CloseAll();
}
ExtSetupSig=CreatePublicHandler(29);
if(ExtSetupSig==NULL)
{
CloseAll();
}
TaskPort=CreatePort("Disk Transfer Motor Task <Stop>",0L);
ReplyPort=CreatePort("Disk Transfer <Stop> Reply",0L);
if((TaskPort==NULL)||(ReplyPort==NULL))
{
ErrorRequest(ERROR_PORT);
CloseAll();
}
MotorTask=CreateProcess(Motor,500,"Disk Transfer Motor Task",2);
if(MotorTask==NULL)
{
DeletePort(TaskPort);
InfoRequest("Kann Motor-Task nicht erstellen.\n");
CloseAll();
}
app=CreateAppItem("ATUtilities Disk Transfer");
if(app!=NULL) AppSignalMask=app->SignalMask; else AppSignalMask=0;
jhword=ExtSetupSig->WordAccess;
jhbyte=ExtSetupSig->ByteAccess;
PortSignal=Port->mp_SigBit;
PortSignalMask=(1L<<PortSignal);
JanusSignal=ExtSetupSig->JanusSignal;
JanusSignalMask=ExtSetupSig->JanusSignalMask;
TaskSignalMask=(1L<<TaskSignal);
WaitSignalMask=PortSignalMask+JanusSignalMask+TaskSignalMask+AppSignalMask;
}
/* Programmende */
VOID CloseAll()
{
if(app) DeleteAppItem(app);
if(MotorTask!=NULL)
{
Message.mn_Node.ln_Type=NT_MESSAGE;
Message.mn_ReplyPort=ReplyPort;
PutMsg(TaskPort,&Message);
WaitPort(ReplyPort);
DeletePort(ReplyPort);
}
if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
if(mem) FreeMem(mem,PUBLIC_PAGESIZE);
if(TaskSignal!=-1) FreeSignal(TaskSignal);
if(Port) DeletePort(Port);
UninstallAll();
if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
if(GfxBase) CloseLibrary(GfxBase);
if(IntuitionBase) CloseLibrary(IntuitionBase);
if(JanusBase) CloseLibrary(JanusBase);
exit(0);
}
/* Einstellungs-Fenster */
BOOL EinstellungenAendern()
{
UBYTE text[40];
BOOL bool,ende;
REGISTER ULONG Class;
REGISTER WORD i,j,id;
register struct Window *win;
register struct RastPort *rp;
register struct Gadget *gad;
register struct IntuiMessage *msg;
register struct TextFont *opal;
#ifdef SHAREWARE
RegCheck();
#endif
win=CreateStdWindow("ATUtilities - Disk Transfer Einstellungen",
75,75,450,122,CLOSEWINDOW|GADGETUP,
ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
ende=FALSE;
if(win!=NULL)
{
rp=win->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
CreateBoolGadget(win,10,15,155,12,"Einstellungen Okay",1);
CreateBoolGadget(win,170,15,155,12,"Programm beenden",2);
CreateBoolGadget(win,335,15,50,12,"Info",3);
CreateBoolGadget(win,390,15,50,12,"Hilfe",4);
for(i=0,j=10;i<6;i++,j++)
{
sprintf(&text,"Laufwerk %ld:",i+1);
CreateBoolGadget(win,33,35+(i*14),120,12,&text,j);
CreateBoolGadget(win,10,35+(i*14),20,12,"!",i+100);
ZeigeLW(rp,i);
}
bool=FALSE;
while(bool==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
Class=msg->Class;
gad=msg->IAddress;
ReplyMsg(msg);
switch(Class)
{
case GADGETUP:
id=gad->GadgetID;
switch(id)
{
case 1:
bool=TRUE;
break;
case 2:
ende=TRUE; bool=TRUE;
break;
case 3:
ShowInfo();
break;
case 4:
Help(HelpName,0);
break;
default:
if((id>=10)&&(id<=15))
{
j=id-10;
EditiereLW(j);
ZeigeLW(rp,j);
}
if((id>=100)&&(id<=105))
{
j=id-100;
if(ud[j].File==FALSE)
{
if(td[j].Valid==TRUE)
{
Bearbeite(j);
}
else
{
MultiRequest("Dieses Device ist nocht nicht verfügbar.",
"Bitte prüfen Sie die Einstellungen.","Okay",0L);
}
}
else
{
BearbeiteFile(j);
}
}
break;
}
break;
case CLOSEWINDOW:
bool=TRUE;
break;
}
}
DeleteStdWindow(win);
}
if(ende) ende=ExitWarning();
return(ende);
}
/* Parameter ändern */
VOID EditiereLW(num)
UWORD num;
{
UBYTE text[10];
BOOL ende,f;
ULONG a,b,c,d;
REGISTER ULONG Class;
REGISTER WORD i,j,id;
UBYTE *bDevice,
*bUnit,
*bBlocksPerTrack,
*bTracks,
*bHeads,
*bMotor;
register struct Window *win;
register struct RastPort *rp;
register struct IntuiMessage *msg;
register struct TextFont *opal;
register struct Gadget *gad,*isFile;
struct FileHandle *fh;
win=CreateStdWindow("Laufwerksparameter editieren",
225,90,400,100,CLOSEWINDOW|GADGETUP,
ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
ende=FALSE;
if(win!=NULL)
{
rp=win->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
CreateBoolGadget(win,10,15,100,12,"Okay",1);
CreateBoolGadget(win,120,15,100,12,"Abbruch",2);
if(ud[num].File==FALSE)
{
isFile=CreateNToggleGadget(win,300,15,80,12,"Als Datei",100);
}
else
{
isFile=CreateSToggleGadget(win,300,15,80,12,"Als Datei",100);
}
bDevice=CreateStringGadget(win,120,30,260,10,&ud[num].Name,100,3);
sprintf(&text,"%ld",ud[num].Unit);
bUnit=CreateIntegerGadget(win,120,45,60,10,&text,4,4);
sprintf(&text,"%ld",ud[num].Heads);
bHeads=CreateIntegerGadget(win,320,45,60,10,&text,5,5);
sprintf(&text,"%ld",ud[num].Tracks);
bTracks=CreateIntegerGadget(win,120,57,60,10,&text,7,6);
sprintf(&text,"%ld",ud[num].SectorsPerTrack);
bBlocksPerTrack=CreateIntegerGadget(win,320,57,60,10,&text,5,7);
sprintf(&text,"%ld",ud[num].Motor);
bMotor=CreateIntegerGadget(win,320,74,60,10,&text,5,8);
WriteText(rp,15,37,"Device/Datei:");
WriteText(rp,15,52,"Unit:");
WriteText(rp,220,52,"S/L-Köpfe:");
WriteText(rp,15,64,"Spuren:");
WriteText(rp,220,64,"Sekt./Spur:");
WriteText(rp,15,82,"Motor-Ausschaltzeit nach x Sekunden:");
ende=FALSE;
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
Class=msg->Class;
gad=msg->IAddress;
ReplyMsg(msg);
switch(Class)
{
case GADGETUP:
id=gad->GadgetID;
switch(id)
{
case 2:
ende=TRUE;
break;
case 1:
j=0;
a=atol(bUnit);
b=atol(bTracks);
c=atol(bHeads);
d=atol(bBlocksPerTrack);
i=atol(bMotor);
if(isFile->Flags & SELECTED) f=TRUE; else f=FALSE;
if(b<2)
{ InfoRequest("Unzulässige Spurenanzahl."); j=1; }
if(c<1)
{ InfoRequest("Unzulässige S/L-Kopfanzahl."); j++; }
if(d<2)
{ InfoRequest("Unzulässige Anzahl von Sektoren/Spur."); j++; }
if(i>180)
{ InfoRequest("Motor-Zeit nicht empfehlenswert (>180s)."); }
if(j==0)
{
if(strcmp(&ud[num].Name,bDevice)) j=1;
if(ud[num].Unit!=a) j=1;
if(ud[num].Tracks!=b) j=1;
if(ud[num].Heads!=c) j=1;
if(ud[num].SectorsPerTrack!=d) j=1;
strcpy(&ud[num].Name,bDevice);
ud[num].Motor=i;
ud[num].Unit=a;
ud[num].Tracks=b;
ud[num].Heads=c;
ud[num].SectorsPerTrack=d;
ud[num].File=f;
if(j==1)
{
td[num].Valid=FALSE;
MultiRequest("Um Probleme mit MS-DOS zu vermeiden, wird",
"das Laufwerk erst nach einem Reset aktiv.",
"Okay",NULL);
}
fh=Open(PrefsName,MODE_NEWFILE);
if(fh!=NULL)
{
Write(fh,&ud,sizeof(struct UDevice)*6);
Close(fh);
}
else
{
InfoRequest("Fehler beim Schreiben der Prefs-Datei.");
}
ende=TRUE;
}
break;
}
break;
case CLOSEWINDOW:
ende=TRUE;
break;
}
}
DeleteStdWindow(win);
}
}
/* Parameter anzeigen */
VOID ZeigeLW(rp,id)
struct RastPort *rp;
UWORD id;
{
UBYTE size[20];
UBYTE text[30];
REGISTER ULONG kb;
kb=(ud[id].Heads*ud[id].Tracks*ud[id].SectorsPerTrack*512)/1024;
if(kb>=10000)
{
sprintf(&size,"%ld MB",kb/1024);
}
else
{
sprintf(&size,"%ld KB",kb);
}
if(ud[id].File==FALSE)
{
sprintf(&text,"%s %s Unit %ld",
&size,&ud[id].Name,ud[id].Unit);
}
else
{
sprintf(&text,"%s %s",&size,&ud[id].Name);
}
WriteText(rp,160,43+(id*14),&text);
}
/* Device-Laufwerk bearbeiten */
VOID Bearbeite(num)
UWORD num;
{
UBYTE text[40];
REGISTER BOOL ende,bool;
REGISTER ULONG Class;
REGISTER WORD i,j,id;
register struct Window *win;
register struct RastPort *rp;
register struct Gadget *gad;
register struct IntuiMessage *msg;
register struct TextFont *opal;
register struct Gadget *verify;
BOOL v;
ULONG BytesPerTrack;
ULONG Track;
UBYTE *FormatMemory;
win=CreateStdWindow("Speichermedium bearbeiten",
225,90,300,76,CLOSEWINDOW|GADGETUP,
ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
ende=FALSE;
if(win!=NULL)
{
rp=win->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
CreateBoolGadget(win,10,12,100,12,"Okay",1);
CreateBoolGadget(win,10,30,119,12,"Hard-Format",2);
CreateBoolGadget(win,10,44,172,12,"Prüfe auf Fehler",3);
verify=CreateSToggleGadget(win,132,30,50,12,"Verify",100);
DrawNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
DrawNTextBorder(win,190,30,100,12,"0");
DrawNTextBorder(win,190,44,100,12,"0 %");
ende=FALSE;
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
Class=msg->Class;
gad=msg->IAddress;
ReplyMsg(msg);
switch(Class)
{
case GADGETUP:
id=gad->GadgetID;
switch(id)
{
case 2:
case 3:
DrawCNTextBorder(win,10,58,280,12,"Kein Fehler aufgetreten.");
if(verify->Flags & SELECTED) v=TRUE; else v=FALSE;
if(id==3)
{
bool=MultiRequest("Wollen Sie den Datenträger auf",
"Fehler überprüfen ?",
"Ja, Prüfen","Nein, Zurück");
}
else
{
bool=MultiRequest("Hard-Format: Alle Daten werden gelöscht!",
"Sind Sie wirklich sicher ?",
"Ja, Format","NEIN! Zurück");
}
if(bool==TRUE)
{
MotorCNT[num]=5;
BytesPerTrack=ud[num].SectorsPerTrack*ud[num].Heads*512;
FormatMemory=AllocMem(BytesPerTrack,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
if(FormatMemory!=NULL)
{
SetDrMd(rp,JAM2);
j=0;
for(Track=0;Track<ud[num].Tracks;Track++)
{
sprintf(&text," %ld ",Track);
DrawNTextBorder(win,190,30,100,12,&text);
sprintf(&text," %3ld %% ",((Track*100)/(ud[num].Tracks-1)));
DrawNTextBorder(win,190,44,100,12,&text);
if(ud[num].File==FALSE)
{
if(id==3)
{
td[num].Request->io_Data=FormatMemory;
td[num].Request->io_Length=BytesPerTrack;
td[num].Request->io_Offset=Track*BytesPerTrack;
td[num].Request->io_Command=CMD_READ;
i=DoIO(td[num].Request);
if(i!=0)
{
if(i==29)
{
InfoRequest("Das Medium ist nicht eingelegt.");
Track=ud[num].Tracks;
}
else
{
sprintf(&text,"Fehler #%ld auf Track %ld.",i,Track);
DrawCNTextBorder(win,10,58,280,12,&text);
}
j++;
}
}
else
{
td[num].Request->io_Data=FormatMemory;
td[num].Request->io_Length=BytesPerTrack;
td[num].Request->io_Offset=Track*BytesPerTrack;
td[num].Request->io_Command=TD_FORMAT;
i=DoIO(td[num].Request);
if(i!=0)
{
sprintf(&text,"Format: Fehler #%ld auf Track %ld.",i,Track);
DrawCNTextBorder(win,10,58,280,12,&text);
j++;
if(i==28)
{
InfoRequest("Das Medium ist schreibgeschützt.");
Track=ud[num].Tracks;
}
else if(i==29)
{
InfoRequest("Das Medium ist nicht eingelegt.");
Track=ud[num].Tracks;
}
}
if((v==TRUE)&&(Track<ud[num].Tracks))
{
td[num].Request->io_Data=FormatMemory;
td[num].Request->io_Length=BytesPerTrack;
td[num].Request->io_Offset=Track*BytesPerTrack;
td[num].Request->io_Command=CMD_READ;
i=DoIO(td[num].Request);
if(i!=0)
{
sprintf(&text,"Verify: Fehler #%ld auf Track %ld.",i,Track);
DrawCNTextBorder(win,10,58,280,12,&text);
j++;
}
}
}
}
}
if(j==0)
{
if(id==3) InfoRequest("Der Datenträger ist fehlerfrei.");
}
else
{
if(id==3)
{
sprintf(&text,"%ld Fehler gefunden worden.",j);
MultiRequest("Bei der Überprüfung sind",&text,"Okay",NULL);
}
else
{
sprintf(&text,"%ld Fehler aufgetreten.",j);
MultiRequest("Bei der Formatierung sind",&text,"Okay",NULL);
}
}
FreeMem(FormatMemory,BytesPerTrack);
}
}
break;
case 1:
ende=TRUE;
break;
}
break;
case CLOSEWINDOW:
ende=TRUE;
break;
}
}
DeleteStdWindow(win);
}
}
/* FAT berechnen */
VOID CalcFAT(num)
UWORD num;
{
REGISTER UWORD anz,i;
REGISTER ULONG bytes,plus,sek,spc;
sek=ud[num].Tracks*ud[num].Heads*ud[num].SectorsPerTrack;
if(sek>4096)
{
bytes=sek*2; /* FAT 16-Bit */
}
else
{
bytes=(sek*3)/2; /* FAT 12-Bit */
}
plus=0;
anz=0;
for(i=0;i<32000;i++)
{
if(plus>=bytes)
{
spc=1;
if(anz>15)
{
do
{
spc=spc*2;
anz=anz/2;
} while(anz>15);
}
jhword->Arg5=anz;
jhbyte->Arg6=spc;
return;
}
else
{
plus+=512;
anz++;
}
}
}
/* File-Laufwerk bearbeiten */
VOID BearbeiteFile(num)
UWORD num;
{
UBYTE text[35];
REGISTER BOOL bool;
REGISTER UBYTE *mem;
REGISTER ULONG i,j,k,l;
register struct FileHandle *fh;
register struct Window *win;
register struct RastPort *rp;
struct TextFont *opal;
struct IntuiMessage *msg;
if(td[num].Valid==FALSE)
{
bool=MultiRequest("Es existiert keine Laufwerksdatei.",
"Möchten Sie eine erstellen ?",
"Ja, Erstellen","Nein, Zurück");
if(bool==TRUE)
{
j=512*ud[num].SectorsPerTrack*ud[num].Heads;
mem=AllocMem(j,MEMF_CLEAR|MEMF_PUBLIC);
if(mem!=NULL)
{
fh=Open(&ud[num].Name,MODE_NEWFILE);
if(fh!=NULL)
{
win=CreateStdWindow("Laufwerksdatei erstellen",
75,90,300,30,GADGETUP|CLOSEWINDOW,
WINDOWCLOSE|WINDOWDEPTH|ACTIVATE|WINDOWDRAG);
if(win!=NULL)
{
opal=GetOpalFont();
rp=win->RPort;
SetFont(rp,opal);
CreateBoolGadget(win,10,15,120,12,"Stop !",1);
bool=FALSE;
if(win!=NULL)
{
for(i=0;i<ud[num].Tracks;i++)
{
sprintf(&text,"Track %ld von %ld",i,ud[num].Tracks);
DrawCNTextBorder(win,140,15,150,12,&text);
k=Write(fh,mem,j);
if(k!=j)
{
InfoRequest("Schreibfehler!");
i=ud[num].Tracks;
bool=TRUE;
}
msg=GetMsg(win->UserPort);
if(msg!=NULL)
{
InfoRequest("Stop!");
i=ud[num].Tracks;
bool=TRUE;
}
}
if(bool==FALSE)
{
td[num].FileHandle=fh;
td[num].Valid=TRUE;
}
else
{
Close(fh);
DeleteFile(&ud[num].Name);
}
}
DeleteStdWindow(win);
}
else
{
Close(fh);
DeleteFile(&ud[num].Name);
ErrorRequest(ERROR_ALLOC);
}
}
else InfoRequest("Laufwerksdatei läßt sich nicht erstellen.");
FreeMem(mem,j);
}
else ErrorRequest(ERROR_ALLOC);
}
}
else
{
win=CreateStdWindow("Laufwerksdatei-Information",75,90,300,90,
CLOSEWINDOW|GADGETUP,
WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
if(win!=NULL)
{
opal=GetOpalFont();
rp=win->RPort;
SetFont(rp,opal);
CreateBoolGadget(win,10,15,120,12,"Okay",1);
sprintf(&text,"Spuren: %ld",ud[num].Tracks);
DrawNTextBorder(win,10,30,280,12,&text);
sprintf(&text,"S/L-Köpfe: %ld",ud[num].Heads);
DrawNTextBorder(win,10,45,280,12,&text);
sprintf(&text,"Sektoren/Spur: %ld",ud[num].SectorsPerTrack);
DrawNTextBorder(win,10,60,280,12,&text);
sprintf(&text,"KBytes: %ld",(ud[num].Tracks*ud[num].SectorsPerTrack*ud[num].Heads)/2);
DrawNTextBorder(win,10,75,280,12,&text);
WaitPort(win->UserPort);
DeleteStdWindow(win);
}
}
}
/* Motor-Kontrollprozeß */
VOID Motor()
{
register struct Message *msg;
geta4();
do
{
Delay(50);
Signal(MainTask,TaskSignalMask);
msg=GetMsg(TaskPort);
}
while(msg==NULL);
DeletePort(TaskPort);
ReplyMsg(msg);
Exit(0);
}
/* Motor ein- und ausschalten */
VOID MotorOnOff(num,status)
UWORD num;
UWORD status;
{
if(td[num].Valid==TRUE)
{
if(ud[num].File==FALSE)
{
td[num].Request->io_Command=TD_MOTOR;
td[num].Request->io_Length=status;
SendIO(td[num].Request);
}
}
}
/* Datenträger formatieren */
VOID Format()
{
REGISTER ULONG tSize;
REGISTER UBYTE *fBuffer;
REGISTER UWORD res,i;
res=0;
if(ud[Active].File==FALSE)
{
tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
if(fBuffer!=NULL)
{
td[Active].Request->io_Data=fBuffer;
td[Active].Request->io_Length=tSize;
td[Active].Request->io_Offset=jhword->Arg2*tSize;
td[Active].Request->io_Command=TD_FORMAT;
i=DoIO(td[Active].Request);
if(i==0)
{
if(jhword->Arg3==1)
{
td[Active].Request->io_Command=CMD_READ;
i=DoIO(td[Active].Request);
if(i!=0) res=3;
}
} else res=2;
MotorCNT[Active]=ud[Active].Motor;
FreeMem(fBuffer,tSize);
}
else res=1;
}
jhword->Arg2=res;
}
/* Datenträger kopieren */
VOID Kopiere()
{
REGISTER ULONG tSize;
REGISTER UBYTE *fBuffer;
REGISTER UWORD res,i;
res=0;
tSize=512*ud[Active].SectorsPerTrack*ud[Active].Heads;
fBuffer=AllocMem(tSize,MEMF_CHIP|MEMF_CLEAR|MEMF_PUBLIC);
if(fBuffer!=NULL)
{
if(ud[Active].File==FALSE)
{
td[Active].Request->io_Data=fBuffer;
td[Active].Request->io_Length=tSize;
td[Active].Request->io_Offset=jhword->Arg2*tSize;
td[Active].Request->io_Command=CMD_READ;
i=DoIO(td[Active].Request);
}
else
{
Seek(td[Active].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
i=Read(td[Active].FileHandle,fBuffer,tSize);
if(i!=tSize) i=1; else i=0;
}
if(i==0)
{
if(ud[jhword->Arg3].File==FALSE)
{
td[jhword->Arg3].Request->io_Data=fBuffer;
td[jhword->Arg3].Request->io_Length=tSize;
td[jhword->Arg3].Request->io_Offset=jhword->Arg2*tSize;
td[jhword->Arg3].Request->io_Command=TD_FORMAT;
i=DoIO(td[jhword->Arg3].Request);
if(i==0)
{
if(jhword->Arg4==1)
{
td[jhword->Arg3].Request->io_Command=CMD_READ;
i=DoIO(td[jhword->Arg3].Request);
if(i!=0) res=4;
}
} else res=3;
}
else
{
Seek(td[jhword->Arg3].FileHandle,jhword->Arg2*tSize,OFFSET_BEGINNING);
i=Write(td[jhword->Arg3].FileHandle,fBuffer,tSize);
if(i!=tSize) res=3;
}
} else res=2;
MotorCNT[Active]=ud[Active].Motor;
MotorCNT[jhword->Arg3]=ud[jhword->Arg3].Motor;
FreeMem(fBuffer,tSize);
} else res=1;
jhword->Arg2=res;
}
/* Information */
VOID ShowInfo()
{
InformationBox("ATUtilities Disk Transfer - Information",
"$VER: Disk Transfer - Version 4.0",
"Copyright (C) 1993 by",
"Thomas Dreibholz",
"All rights reserved.",
"AT:Icons/Utility");
}
#ifdef SHAREWARE
VOID RegCheck()
{
REGISTER BOOL bool;
REGISTER UWORD i,j;
register struct TextFont *opal;
register struct FileHandle *fh;
register struct RastPort *rp;
register struct Window *RegWindow;
bool=FALSE;
fh=Open("SYS:PC/ATUtilities/ATUtilities.reg",MODE_OLDFILE);
if(fh!=NULL)
{
Read(fh,&Kunde,sizeof(struct Kunde));
Close(fh);
i=CHECKSTR(&Kunde.Code,&Kunde.Vorname,CODE_VN,VN1);
i+=CHECKSTR(&Kunde.Code,&Kunde.Nachname,CODE_NN,NN1);
i+=CHECKSTR(&Kunde.Code,&Kunde.Straße,CODE_ST,ST1);
i+=CHECKSTR(&Kunde.Code,&Kunde.Land,CODE_LA,LA1);
i+=CHECKSTR(&Kunde.Code,&Kunde.Postleitzahl,CODE_PL,PL1);
i+=CHECKSTR(&Kunde.Code,&Kunde.Ort,CODE_OR,OR1);
i+=CHECKCODE(&Kunde.Code);
if(i==0)
{
j=GETPRG(Kunde.Code);
if(j & PROG_DISKTRANSFER) bool=TRUE;
}
}
if(bool==FALSE)
{
RegWindow=CreateStdWindow(NULL,75,100,450,72,0L,0L);
if(RegWindow!=NULL)
{
rp=RegWindow->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
SelectStdFPen(rp);
WriteText(rp,15,10,"Disk Transfer - Unregistrierte Version");
WriteText(rp,15,23,"Dieses Programm ist Shareware! Möchten Sie es");
WriteText(rp,15,33,"regelmäßig nutzen, so müssen Sie es registrieren");
WriteText(rp,15,43,"lassen! Weitere Informationen dazu finden Sie in");
WriteText(rp,15,53,"der Datei \"Registrierung.DOK\" und im Hilfe-");
WriteText(rp,15,63,"system unter \"Shareware-Registrierung\".");
Delay(500);
DeleteStdWindow(RegWindow);
}
}
}
#endif
BOOL AddCache(block,offset,len)
UBYTE *block;
ULONG offset;
UWORD len;
{
REGISTER UBYTE *copy;
register struct CacheBlock *cb,*old;
if(td[Active].FirstCacheBlock==NULL)
{
td[Active].Request->io_Command=TD_PROTSTATUS;
DoIO(td[Active].Request);
if(td[Active].Request->io_Actual!=0) return(FALSE);
/* td[Active].Request->io_Command=TD_CHANGENUM;
DoIO(td[Active].Request);
if(td[Active].Request->io_Actual!=td[Active].Changes) return(FALSE);
*/
}
if((AvailMem(MEMF_PUBLIC|MEMF_CHIP))<225000) return(FALSE);
/*
cb=AllocRemember(&td[Active].CacheRemember,sizeof(struct CacheBlock),MEMF_PUBLIC|MEMF_CLEAR);
if(cb==NULL) return(FALSE);
copy=AllocRemember(&td[Active].CacheRemember,len,MEMF_PUBLIC|MEMF_CHIP);
if(copy==NULL) return(FALSE);
*/
cb=AllocMem(sizeof(struct CacheBlock),MEMF_PUBLIC|MEMF_CLEAR);
if(cb==NULL) return(FALSE);
copy=AllocMem(len,MEMF_PUBLIC|MEMF_CHIP);
if(copy==NULL) return(FALSE);
cb->Offset=offset;
cb->Length=len;
cb->Memory=copy;
cb->Changes=td[Active].Changes;
CopyMemQuick(block,copy,len);
if(td[Active].FirstCacheBlock==NULL)
td[Active].FirstCacheBlock=cb;
else
{
old=td[Active].FirstCacheBlock;
if(old->NextCacheBlock!=NULL)
{
while(old->NextCacheBlock!=NULL)
old=old->NextCacheBlock;
}
old->NextCacheBlock=cb;
}
xxx+=len;
printf("ADD: %lx L=%ld O=%ld xxx=%ld\n",copy,len,offset,xxx);
MotorCNT[Active]=2;
MotorOnOff(Active,1);
jhword->Arg2=0;
puts("return");
return(TRUE);
}
VOID WriteCache(ii)
UWORD ii;
{
register struct CacheBlock *cb;
printf("AUSGABE %ld\n",ii);
if(td[ii].FirstCacheBlock!=NULL)
{
cb=td[ii].FirstCacheBlock;
do
{
/* if(cb->Changes==td[ii].Changes)
{ */
td[ii].Request->io_Data=cb->Memory;
td[ii].Request->io_Offset=cb->Offset;
td[ii].Request->io_Length=cb->Length;
td[ii].Request->io_Command=CMD_WRITE;
printf("WRITE: %lx L=%ld O=%ld\n",cb->Memory,cb->Length,cb->Offset);
DoIO(td[ii].Request);
FreeMem(cb->Memory,cb->Length);
/* } */
cb=cb->NextCacheBlock;
} while(cb!=NULL);
td[ii].Request->io_Command=CMD_UPDATE;
DoIO(td[ii].Request);
/* FreeRemember(&td[ii].CacheRemember,TRUE); */
td[ii].CacheRemember=NULL;
td[ii].FirstCacheBlock=NULL;
printf("-------------------------- %ld Bytes\n",xxx);
xxx=0;
}
}